﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GcmpGuiMainFrame.h"
#include <QMdiSubWindow>
#include <QtGui/QWheelEvent>
#include <WeakPtr.h>
#include "IUiViewParent.h"
#include <QMdiArea>

namespace gcmp
{
    class IUiView;
    class IMenuItemDefinition;
}

class GmSubFrame : public QMdiSubWindow, public gcmp::IUiViewParent
{
    Q_OBJECT

public:
    GmSubFrame(int iUIDocID, QWidget *parent = 0, Qt::WindowFlags flags = 0);
    virtual ~GmSubFrame();

    // 通过程序来关闭请调用此函数
    bool CloseProgrammactially();

    // 通过主窗口被动关闭请调用此函数
    bool CloseByMainFrameAutomatically();

    //void SetView(gcmp::OwnerPtr<gcmp::GmView> opGmView);
    void SetView(gcmp::IUiView* pGmView);
    void OnViewClosed();// 注意：加这个方法是为了在GmView关闭后，将缓存的GmView指针置空的！
    gcmp::IUiView *GetView() ;

    //////////////////////////////////////////////////////////////////////////
    virtual UInt64 GetId() override;
    virtual bool Activate() override;
   
    virtual bool Close() override;

    //////////////////////////////////////////////////////////////////////////
    bool OnWindowActivated();

public slots:
    void OnWindowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState);
    //////////////////////////////////////////////////////////////////////////

    

private:
    bool IsInEditMode();
    //bool AllowDocumentToBeClosed();

    friend class GcmpUiViewContextMenuEventHandler;

protected: // 重载基类函数。
    virtual void closeEvent(QCloseEvent *event)Q_DECL_OVERRIDE;
    virtual void moveEvent(QMoveEvent * pEvent) override;
    virtual void resizeEvent(QResizeEvent * pEvent) override;

signals:
    void NotifyCloseView(QMdiSubWindow * ); //自定义信号

private:
    // 所关联的UI doc的标识符。
    int   m_iUIDocID = -1;
    gcmp::WeakPtr<gcmp::IUiView> m_wpGmView;
};




